﻿using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace Super.Hmi.Converters
{
    /// <summary>
    /// 将集合的元素数量转换为可见性
    /// </summary>
    public class CountToVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is IEnumerable<object> items && int.TryParse(parameter?.ToString(), out int count))
            {
                if (items.Count() > count)
                {
                    return Visibility.Visible;
                }
            }
            return Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
